//
//  LoopFMDBManager.swift
//  LoopWeibo
//
//  Created by loop安 on 2016/12/29.
//  Copyright © 2016年 loop. All rights reserved.
//

import UIKit
import FMDB

class LoopFMDBManager: NSObject {

    static let shared:LoopFMDBManager = LoopFMDBManager()
    
    let queue : FMDatabaseQueue
    
    override init() {
        let path = (NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).last! as NSString).appendingPathComponent("weibo.db")
        queue = FMDatabaseQueue(path: path)
        super.init()
        
        createCacheTable()
    
    }
    
    private func createCacheTable(){
    
        let sql = "CREATE TABLE IF NOT EXISTS t_Weibo (statusId TEXT PRIMARY KEY NOT NULL, status TEXT, userId TEXT, create_date TEXT DEFAULT (datetime('now','localtime')));"
        queue.inTransaction { (db, rollback) in
            let res = db!.executeStatements(sql)
            if res{
                print("建表成功")
            }else{
                print("建表失败")
                rollback?.pointee = true
            }
        }
    }
    
    
    
}
